<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "order".
 *
 * @property string $id ID
 * @property string $alipay 支付宝账号
 * @property string $name 姓名
 * @property string $status 状态:10=取件,20=签收,30=验货,40=放款
 * @property string $mobile
 * @property string $address 地址
 * @property int $product_id 商品ID
 * @property int $member_id 用户ID
 * @property string $maketime 预约时间
 * @property int $created_at 创建时间
 * @property int $updated_at
 * @property int $sign_at
 * @property int $pick_at
 * @property int $examine_al
 * @property int $accomplish
 * @property int $is_cancel  取消订单
 */
class Order extends \yii\db\ActiveRecord
{
    const STATUS_START= 0; //待取件
    const STATUS_INIT = 10; //取件
    const STATUS_EXAMINE = 20; //签收
    const STATUS_FAIL = 30; //验货
    const STATUS_SUCCESS=40;//放款完成

    const IS_YES='1'; //取消
    const IS_NO='0';   //未取消
    /**
     * {@inheritdoc}
     */

    public static $status=[
        self::STATUS_START=>'待取件',
        self::STATUS_INIT=>'取件',
        self::STATUS_EXAMINE=>'签收',
        self::STATUS_FAIL=>'验机',
        self::STATUS_SUCCESS=>'成交收款'
    ];

    public static $isCancel=[
        self::IS_YES=>'取消订单',
        self::IS_NO=>"未取消",
        ];

    public static function tableName()
    {
        return 'order';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['alipay','name','mobile','address','maketime','is_cancel'], 'required'],
            [['product_id',  'created_at', 'updated_at', 'sign_at'], 'integer'],
            [['maketime'], 'safe'],
            [['alipay', 'name','mobile','address'], 'string', 'max' => 255,],
            [['mobile'], 'string', 'max' => 11],
            [['address'], 'string', 'max' => 555],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'alipay' => '支付宝账号',
            'name' => '姓名',
            'status' => '状态',
            'mobile' => '手机号',
            'address' => '地址',
            'product_name' => '商品名',
            'user_id' => '用户ID',
            'maketime' => '预约时间',
            'created_at' => '创建时间',
            'updated_at'=>'修改时间',
            'is_cancel'=>'是否取消'
        ];
    }

    public function getProductInfo()
    {
        return $this->hasone(Product::class,['id'=>'product_id']);
    }
}
